package bingo.rpc.framework.cluster.impl;

import org.apache.commons.lang3.StringUtils;

/**
 * @author hujinsheng
 * @project bingo
 * @create 2017-12-14 13:39
 **/
public enum ClusterStrategyEnum {

    /**随机*/
    Random("Random"),
    /**加权随机*/
    WeightRandom("WeightRandom"),
    /**轮询*/
    RoundRobin("RoundRobin"),
    /**加权轮询*/
    WeightRoundRobin("WeightRoundRobin"),
    /**原地址hash*/
    Hash("Hash");


    private String code;

    private  ClusterStrategyEnum(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public static ClusterStrategyEnum queryByCode(String code){
        if(StringUtils.isBlank(code)){
            return null;
        }
        for(ClusterStrategyEnum strategy:values()){

            if(StringUtils.equals(code,strategy.getCode())){
                return strategy;
            }
        }
        return null;
    }
}
